package model_do

import (
	"fmt"
	"gitee.com/wzpwzy/gogii/conf"
	"gitee.com/wzpwzy/gogii/generator/model"
	"gitee.com/wzpwzy/gogii/generator/service/dao"
	"gitee.com/wzpwzy/gogii/tools"
	_ "github.com/go-sql-driver/mysql"
)

/**
*fmt.Scanln(&table) //方法-
*fmt.Scanf("%d %s %f %t",&age,&name,&score,&isVIP)
 */
func main1() {
	//实现功能：代码生成器
	//方式1：Scanln
	var table string
	var path string
	//录入数据的时候，类型一定要匹配，因为底层会自动判定类型的
	fmt.Scanln(&table)
	//数据库配置
	source := "wwj:kwy@tcp(121.41.103.105:3306)/data-stat?charset=utf8&parseTime=True&loc=Local"
	//source := "wwj:kwy@tcp(121.41.103.105:3306)/new_kwy_order?charset=utf8&parseTime=True&loc=Local"
	Column(source, table, path)
	//beego.Run()
}

/*
*一键生成所有文件
 */
func Column(soure string, table string, path string) {
	//初始化配置
	var MysqlConfigDbConf = conf.DbConf{
		DbName: "data-stat",
		Url:    soure,
		Prefix: "tj_",
	}
	conf.MasterDbConfig = MysqlConfigDbConf
	//初始化Mysql连接池
	mysql := tools.GetMysqlInstance().InitMysqlPool()
	if !mysql {
		fmt.Println("init database pool failure...")
	}
	path = "./common/models/stat/"
	var options conf.Options
	var modelList []model.Table
	modelList = model.Genertate(path, 0, table) //生成所有表信息
	for _, model := range modelList {
		options.Namespace = "stat"
		options.Name = model.Name
		options.ModelsNamespace = "data_summary/common/models/stat"
		options.Path = "./service/dao/stat/"
		dao.CreateDao(options)
		//service.GenerateService(options)
	}

}
